}
impl Target {
- fn blank() -> Target {
+ fn with_path(src_path: PathBuf) -> Target {
+ assert!(src_path.is_absolute());
Target {
kind: TargetKind::Bin,
name: String::new(),
- src_path: PathBuf::new(),
+ src_path: src_path,
doc: false,
doctest: false,
harness: true,
pub fn lib_target(name: &str,
crate_targets: Vec<LibKind>,
- src_path: &Path) -> Target {
+ src_path: PathBuf) -> Target {
Target {
kind: TargetKind::Lib(crate_targets),
name: name.to_string(),
- src_path: src_path.to_path_buf(),
doctest: true,
doc: true,
- ..Target::blank()
+ ..Target::with_path(src_path)
}
}
- pub fn bin_target(name: &str, src_path: &Path) -> Target {
+ pub fn bin_target(name: &str, src_path: PathBuf) -> Target {
Target {
kind: TargetKind::Bin,
name: name.to_string(),
- src_path: src_path.to_path_buf(),
doc: true,
- ..Target::blank()
+ ..Target::with_path(src_path)
}
}
/// Builds a `Target` corresponding to the `build = "build.rs"` entry.
- pub fn custom_build_target(name: &str, src_path: &Path) -> Target {
+ pub fn custom_build_target(name: &str, src_path: PathBuf) -> Target {
Target {
kind: TargetKind::CustomBuild,
name: name.to_string(),
- src_path: src_path.to_path_buf(),
for_host: true,
benched: false,
tested: false,
- ..Target::blank()
+ ..Target::with_path(src_path)
}
}
- pub fn example_target(name: &str, src_path: &Path) -> Target {
+ pub fn example_target(name: &str, src_path: PathBuf) -> Target {
Target {
kind: TargetKind::Example,
name: name.to_string(),
- src_path: src_path.to_path_buf(),
benched: false,
- ..Target::blank()
+ ..Target::with_path(src_path)
}
}
- pub fn test_target(name: &str, src_path: &Path) -> Target {
+ pub fn test_target(name: &str, src_path: PathBuf) -> Target {
Target {
kind: TargetKind::Test,
name: name.to_string(),
- src_path: src_path.to_path_buf(),
benched: false,
- ..Target::blank()
+ ..Target::with_path(src_path)
}
}
- pub fn bench_target(name: &str, src_path: &Path) -> Target {
+ pub fn bench_target(name: &str, src_path: PathBuf) -> Target {
Target {
kind: TargetKind::Bench,
name: name.to_string(),
- src_path: src_path.to_path_buf(),
tested: false,
- ..Target::blank()
+ ..Target::with_path(src_path)
}
}
examples: Vec<PathBuf>,
tests: Vec<PathBuf>,
benches: Vec<PathBuf>,
+
}
impl Layout {
let new_build = self.maybe_custom_build(&project.build, &layout.root, &mut warnings);
// Get targets
- let targets = normalize(&lib,
+ let targets = normalize(&layout.root,
+ &lib,
&bins,
new_build,
&examples,
}
}
-fn normalize(lib: &Option<TomlLibTarget>,
+fn normalize(package_root: &Path,
+ lib: &Option<TomlLibTarget>,
bins: &[TomlBinTarget],
custom_build: Option<PathBuf>,
examples: &[TomlExampleTarget],
});
}
- fn lib_target(dst: &mut Vec<Target>, l: &TomlLibTarget) {
+ let lib_target = |dst: &mut Vec<Target>, l: &TomlLibTarget| {
let path = l.path.clone().unwrap_or(
PathValue::Path(Path::new("src").join(&format!("{}.rs", l.name())))
);
};
let mut target = Target::lib_target(&l.name(), crate_types,
- &path.to_path());
+ package_root.join(path.to_path()));
configure(l, &mut target);
dst.push(target);
- }
+ };
- fn bin_targets(dst: &mut Vec<Target>, bins: &[TomlBinTarget],
- default: &mut FnMut(&TomlBinTarget) -> PathBuf) {
+ let bin_targets = |dst: &mut Vec<Target>, bins: &[TomlBinTarget],
+ default: &mut FnMut(&TomlBinTarget) -> PathBuf| {
for bin in bins.iter() {
let path = bin.path.clone().unwrap_or_else(|| {
PathValue::Path(default(bin))
});
- let mut target = Target::bin_target(&bin.name(), &path.to_path());
+ let mut target = Target::bin_target(&bin.name(), package_root.join(path.to_path()));
configure(bin, &mut target);
dst.push(target);
}
- }
+ };
- fn custom_build_target(dst: &mut Vec<Target>, cmd: &Path) {
+ let custom_build_target = |dst: &mut Vec<Target>, cmd: &Path| {
let name = format!("build-script-{}",
cmd.file_stem().and_then(|s| s.to_str()).unwrap_or(""));
- dst.push(Target::custom_build_target(&name, cmd));
- }
+ dst.push(Target::custom_build_target(&name, package_root.join(cmd)));
+ };
- fn example_targets(dst: &mut Vec<Target>,
- examples: &[TomlExampleTarget],
- default: &mut FnMut(&TomlExampleTarget) -> PathBuf) {
+ let example_targets = |dst: &mut Vec<Target>,
+ examples: &[TomlExampleTarget],
+ default: &mut FnMut(&TomlExampleTarget) -> PathBuf| {
for ex in examples.iter() {
let path = ex.path.clone().unwrap_or_else(|| {
PathValue::Path(default(ex))
});
- let mut target = Target::example_target(&ex.name(), &path.to_path());
+ let mut target = Target::example_target(&ex.name(), package_root.join(path.to_path()));
configure(ex, &mut target);
dst.push(target);
}
- }
+ };
- fn test_targets(dst: &mut Vec<Target>,
- tests: &[TomlTestTarget],
- default: &mut FnMut(&TomlTestTarget) -> PathBuf) {
+ let test_targets = |dst: &mut Vec<Target>,
+ tests: &[TomlTestTarget],
+ default: &mut FnMut(&TomlTestTarget) -> PathBuf| {
for test in tests.iter() {
let path = test.path.clone().unwrap_or_else(|| {
PathValue::Path(default(test))
});
- let mut target = Target::test_target(&test.name(), &path.to_path());
+ let mut target = Target::test_target(&test.name(), package_root.join(path.to_path()));
configure(test, &mut target);
dst.push(target);
}
- }
+ };
- fn bench_targets(dst: &mut Vec<Target>,
- benches: &[TomlBenchTarget],
- default: &mut FnMut(&TomlBenchTarget) -> PathBuf) {
+ let bench_targets = |dst: &mut Vec<Target>,
+ benches: &[TomlBenchTarget],
+ default: &mut FnMut(&TomlBenchTarget) -> PathBuf| {
for bench in benches.iter() {
let path = bench.path.clone().unwrap_or_else(|| {
PathValue::Path(default(bench))
});
- let mut target = Target::bench_target(&bench.name(), &path.to_path());
+ let mut target = Target::bench_target(&bench.name(), package_root.join(path.to_path()));
configure(bench, &mut target);
dst.push(target);
}
- }
+ };
let mut ret = Vec::new();
use cargotest::support::{project, execs, main_file, basic_bin_manifest};
use hamcrest::{assert_that};
-fn remove_all_whitespace(s: &str) -> String {
- s.split_whitespace().collect()
-}
-
-fn read_manifest_output() -> String {
- remove_all_whitespace(r#"
+static MANIFEST_OUTPUT: &'static str = r#"
{
"name":"foo",
"version":"0.5.0",
"targets":[{
"kind":["bin"],
"name":"foo",
- "src_path":"src[..]foo.rs"
+ "src_path":"[..][/]foo[/]src[/]foo.rs"
}],
"features":{},
"manifest_path":"[..]Cargo.toml"
-}"#)
-}
+}"#;
#[test]
fn cargo_read_manifest_path_to_cargo_toml_relative() {
.arg("--manifest-path").arg("foo/Cargo.toml")
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
- .with_stdout(read_manifest_output()));
+ .with_json(MANIFEST_OUTPUT));
}
#[test]
.arg("--manifest-path").arg(p.root().join("Cargo.toml"))
.cwd(p.root().parent().unwrap()),
execs().with_status(0)
- .with_stdout(read_manifest_output()));
+ .with_json(MANIFEST_OUTPUT));
}
#[test]
assert_that(p.cargo_process("read-manifest")
.cwd(p.root()),
execs().with_status(0)
- .with_stdout(read_manifest_output()));
+ .with_json(MANIFEST_OUTPUT));
}